﻿using AutoMapper;
using System.Linq;
using Windows.Admin.Application.Service;
using Windows.Admin.Application.Service.User.Dtos;
using Windows.Admin.Contract;
using Windows.Admin.Domain;
using Windows.Infrastructure.Share.Extensions;
using Windows.SeedWord;

namespace Windows.Admin.Application
{
    public class DomainToDtoMappingProfile : Profile
    {
        /// <summary>
        /// 配置构造函数，用来创建关系映射
        /// </summary>
        public DomainToDtoMappingProfile()
        {
            // CreateMap<User, UserResponse>()
            // .ForMember(
            // dto => dto.OrganizationIds,
            // domain => domain.MapFrom(src => src.Organization_User.Select(s=>s.OrganizationId).ToList())
            // ).ForMember(
            // dto => dto.RoleIds,
            // domain => domain.MapFrom(src => src.Role_User.Select(s => s.RoleId).ToList())
            // );

            // CreateMap<Module, ModuleOperateResponse>().ForMember(
            //   dto => dto.TypeName,
            //   domain => domain.MapFrom(src => src.Type.GetDescription<ModuleTypeEnum>())
            //);
            // CreateMap<Module, ComboBoxTreeResponse>();

            CreateMap<App, AppResponse>();
            CreateMap<Role, RoleResponse>();
            CreateMap<User, LoginResponse>();
            CreateMap<User, CurrentUserResponse>();
            CreateMap<User, UserResponse>().ForMember(
               dto => dto.RoleIds,
               domain => domain.MapFrom(src => src.Role_Users!.Select(s=>s.RoleId))
            );
            CreateMap<Employee, EmployeeResponse>().ForMember(
               dto => dto.GenderName,
               domain => domain.MapFrom(src => src.Gender ? "男" : "女")
            ).ForMember(
               dto => dto.MarriageName,
               domain => domain.MapFrom(src => src.Marriage ? "已婚" : "未婚")
            ).ForMember(
               dto => dto.UserName,
               domain => domain.MapFrom(src => src.User == null ? "" : src.User.UserName)
            ).ForMember(
               dto => dto.OrganizationIds,
               domain => domain.MapFrom(src => src.Organization_Employees == null ? null : src.Organization_Employees.Select(x => x.OrganizationId))
            );
            CreateMap<Employee, ChatEmployeeResponse>().ForMember(
               dto => dto.GenderName,
               domain => domain.MapFrom(src => src.Gender ? "男" : "女")
            )
            .ForMember(
               dto => dto.OrganizationIds,
               domain => domain.MapFrom(src => src.Organization_Employees == null ? null : src.Organization_Employees.Select(x => x.OrganizationId))
            );
            CreateMap<Privilege, PrivilegeResponse>();
            CreateMap<User, ChatUserResponse>().ForMember(
               dto => dto.Name,
               domain => domain.MapFrom(src => src.Employees == null ? null : src.Employees.Select(x => x.Name).FirstOrDefault())
            );
            // CreateMap<Role, RoleResponse>();
            // CreateMap<LogOperate, LogOperateResponse>();
            // CreateMap<LogLogin, LogLoginResponse>();

            CreateMap<Organization, OrganizationResponse>();
            // CreateMap<Organization, ComboBoxTreeResponse>();

            // CreateMap<Dictionary, DictionaryResponse>();
        }
    }
}
